import 'package:flutter/material.dart';

class Gooditem extends StatefulWidget {
   Gooditem({super.key,required this.goodItem});

   Map goodItem;

  @override
  State<Gooditem> createState() => _GooditemState();
}

class _GooditemState extends State<Gooditem> {
  Map goodItem = {};
  String status = '';
  @override
  void initState() {
    super.initState();
      goodItem = widget.goodItem;
    if(goodItem.isNotEmpty) {
      status = getStatus(goodItem['status']);
    }
   
  }
  String getStatus(int status) {
    if(status == 1) {
      return "待提货";
    } else if(status == 2) {
      return "在途";
    } else if(status == 3) {
      return "改派";
    } else if(status == 4) {
      return "已交付";
    } else if(status == 5) {
      return "已作废";
    } else if(status == 6) {
      return "已完成";
    } else {
      return "未知";
    }
  }
  @override
  Widget build(BuildContext context) {
     return   Container(
      margin: EdgeInsets.all(10),
      padding: EdgeInsets.all(10),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(20)
      ),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.start,
        children: [
          Container(
            padding: EdgeInsets.all(10),
            decoration: BoxDecoration(
              border: Border(
                bottom: BorderSide(color: Color(0xFFEF4F3F),width: 0.1)
              )
            ),
            child: Column(
              children: [
                      //1:任务编号
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text('任务编号： ${goodItem['transportTaskId'] ?? ''}',style: TextStyle(fontSize: 16,fontWeight: FontWeight.bold),),
                    Container(
                      padding: EdgeInsets.all(3),
                      decoration: BoxDecoration(
                        border: Border.all(color: Color(0xFFEF4F3F),width: 2),
                        borderRadius: BorderRadius.all(Radius.circular(10)),
                      ),
                      child: Text(status,style: TextStyle(color: Color(0xFFEF4F3F),fontSize: 14,),),
                    )
                  ],
                ),
                SizedBox(height: 10,),
                //2:起点
                Row(
                  mainAxisAlignment: MainAxisAlignment.start,
                  children: [
                    Container(
                      decoration: BoxDecoration(
                        shape: BoxShape.circle,
                        color: Colors.black
                      ),
                      child: Text('起',style: TextStyle(fontSize: 10,color: Colors.white),),
                    ),
                    SizedBox(width: 10,),
                    Expanded(
                      flex: 1,
                      child: Text(goodItem['startAddress'] ?? '',style: TextStyle(color: Colors.grey),),
                    )
                  ],
                ),
                SizedBox(height: 10,),
                //3:终点
                Row(
                  mainAxisAlignment: MainAxisAlignment.start,
                  children: [
                    Container(
                      decoration: BoxDecoration(
                        shape: BoxShape.circle,
                        color: Colors.black
                      ),
                      child: Text('止',style: TextStyle(fontSize: 10,color: Color(0xFFEF4F3F)),),
                    ),
                    SizedBox(width: 10,),
                    Expanded(
                      flex: 1,
                      child: Text(goodItem['endAddress'] ?? '',style: TextStyle(color: Colors.grey),),
                    )
                  ],
                ),
              ],
            ),
          ),
          //4:提货
          Container(
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Text('提货时间',style: TextStyle(color: Colors.grey,fontSize: 12),),
                    Text(goodItem['planArrivalTime'] ?? '',style: TextStyle(color: Colors.grey,fontSize: 12),)
                  ],
                ),
                ElevatedButton(
                  onPressed: (){}, 
                  style: ButtonStyle(
                    backgroundColor: WidgetStateProperty.all(const Color(0xFFEF4F3F)),
                  ),
                  child: Text('提货',style: TextStyle(color: Colors.white),)
                )
              ],
            ),
          )
        ],
      ),
    );
  }
}